<%--
  Created by IntelliJ IDEA.
  User: 晨
  Date: 2018/3/2
  Time: 14:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>驾考宝典</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">驾考宝典</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item" id="main"><a>主页</a></li>
            <c:if test="${!empty choice}">
                <li class="layui-nav-item">
                    <a href="javascript:;">${choice.menuEnum.name}</a>
                    <c:if test="${! empty choice.courses}">
                        <dl class="layui-nav-child">
                            <c:forEach var="courses" items="${choice.courses}">
                                <c:if test="${!empty courses}">
                                    <dd><a onclick="onChoice(this)" href="javascript:;"
                                           ails="${courses.id}">${courses.name}</a></dd>
                                </c:if>
                            </c:forEach>
                        </dl>
                    </c:if>
                </li>

            </c:if>

            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a>邮件管理</a></dd>
                    <dd><a>消息管理</a></dd>
                    <dd><a>授权管理</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    ${user.userName}
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;">基本资料</a></dd>
                    <dd><a href="javascript:;">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="javascript:exit()">退了</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <c:if test="${!empty list}">
                    <c:forEach var="menu" items="${list}">
                        <c:if test="${!empty menu}">
                            <li class="layui-nav-item layui-nav-itemed">
                                <a class="" href="javascript:;">${menu.menuEnum.name}</a>

                                <c:if test="${!empty menu.courses}">
                                    <dl class="layui-nav-child">
                                        <c:forEach var="courses" items="${menu.courses}">
                                            <c:if test="${!empty courses}">
                                                <dd><a onclick="onMenu(this)" href="javascript:;"
                                                       pid="${menu.menuEnum.code}"
                                                       ails="${courses.id}"
                                                       showtop="${courses.showTop}"
                                                >${courses.name}</a></dd>
                                            </c:if>
                                        </c:forEach>
                                    </dl>
                                </c:if>

                            </li>
                        </c:if>
                    </c:forEach>
                </c:if>
            </ul>


        </div>
    </div>

    <div class="layui-body" style="bottom: 0px">
        <!-- 内容主体区域 -->
        <IFRAME id="body" marginWidth=0 marginHeight=0 frameBorder=0
                width="100%" scrolling=no height="100%"></IFRAME>
    </div>

    <%-- <div class="layui-footer">
         <!-- 底部固定区域 -->
         © layui.com - 底部固定区域
     </div>--%>
</div>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>
    var element;
    var layer;
    //标识 当前是否是处于添加题目状态
    var isChoice = false;
    //JavaScript代码区域
    layui.use(['element', 'layer'], function () {
        element = layui.element;
        layer = layui.layer;
        element.init();
        click("main");
    });


    function click(id) {
        $("#" + id).click();
    }
    /**
     * 点击题库管理
     */
    function onChoice(e) {
        isChoice = true;
        $("#body").attr('src', '${pageContext.request.contextPath}/choice/index?userName=${user.userName}&courseId=' + e.getAttribute("ails"));
    }

    function onMenu(e) {
        if (isChoice) {
            //询问框
            layer.confirm('是否放弃添加题库,跳转主界面？', {
                btn: ['取消', '放弃'] //按钮
            }, function (index) {
                layer.close(index);
            }, function () {
                isChoice = false;
                onMeuns(e);

            });
        }else {
            onMeuns(e);
        }
    }


     function onMeuns(e){
         click("main");
         //询问框
         if(e.getAttribute("pid")==1 && e.getAttribute("showtop")==1){//练习模式
             layer.confirm('请选择练习模式？', {
                 btn: ['答题', '学习'] //按钮
             }, function (index) {
                 $("#body").attr('src', '${pageContext.request.contextPath}/menu/menu?userName=${user.userName}&menuId=' + e.getAttribute("pid") + '&courseId=' + e.getAttribute("ails"));
                 layer.close(index);
             }, function () {
                 $("#body").attr('src', '${pageContext.request.contextPath}/menu/menu?userName=${user.userName}&menuId=' + e.getAttribute("pid") + '&courseId=' + e.getAttribute("ails")+'&show=1');
             });
         }else {
             $("#body").attr('src', '${pageContext.request.contextPath}/menu/menu?userName=${user.userName}&menuId=' + e.getAttribute("pid") + '&courseId=' + e.getAttribute("ails"));
         }
     }
    function exit() {
        window.location.href = '${pageContext.request.contextPath}';
    }


</script>
</body>
</html>
